﻿using System;
using System.Collections.Generic;

namespace Chimp.Core
{
    public class AppState : JointNode
    {
        public AppState ( string name, JointApp p )
        {
            Auto = false;
            Name = name;
            SetData ( p );
        }

        public bool Auto { get; set; }

        public override void WriteOutput ( )
        {
            l ( " public class " + Name + " : ChimpState\n    {" );
            ParseVars ( Vars );
            WriteNodes ( );
            l ( "}" );
        }

      

        public override void ParseNode ( )
        {
            Vars = new Dictionary<string, Var>();
            if ( PeekTok ( ) == "Auto" )
            {
                Auto = true;
                GetTok ( );
            }
            while ( !Eof )
            {
                string t = GetTok ( );

                switch ( t )
                {
                    case "Var":

                        VarList vl;
                        vl = GetVars ( );
                        break;
                    case "List":

                        VarList vl2;
                        vl2 = GetVars ( );
                        SetToList ( vl2 );

                        break;
                    case "Event":

                        t = GetTok ( );
                        Console.WriteLine ( "Parsing:" + t );
                        SetNode ( t, new JointBasic ( t, this ) );


                        break;
                    case "End":
                        return;
                    default:
                        Console.WriteLine ( "Syntax error:" + t + "!" );
                        return;
                        break;
                }
            }
        }


    }
}